<template>
<div>
  <el-dialog
    width="30%"
    :title="'报废明细'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="100px" size="mini" label-position="left">
      <el-form-item label="工夹具代码" prop="code">
        <el-input v-model="dataForm.code" placeholder="工夹具代码" disabled></el-input>
      </el-form-item>
      <el-form-item label="工夹具序列号" prop="seqId">
        <el-input v-model="dataForm.seqId" placeholder="工夹具序列号" disabled></el-input>
      </el-form-item>
      <el-form-item label="报废原因" prop="scrapReason">
        <el-input v-model="dataForm.scrapReason" placeholder="报废原因" disabled></el-input>
      </el-form-item>
      <el-form-item label="故障图片" prop="scrapPhotoUrl">
        <img width="25%" :src="dataForm.scrapPhotoUrl">
      </el-form-item>
      <el-form-item label="申请时间" prop="submitTime">
        <el-input v-model="dataForm.submitTime" placeholder="申请时间" disabled></el-input>
      </el-form-item>
      <el-form-item label="审批状态" prop="status">
        <el-input v-model="dataForm.status" placeholder="审批状态" :value="displayValue" disabled></el-input>
      </el-form-item>
      <el-form-item label="初审人" prop="firstAcceptorName">
        <el-input v-model="dataForm.firstAcceptorName" placeholder="初审人" disabled></el-input>
      </el-form-item>
      <el-form-item label="初审时间" prop="firstTime">
        <el-input v-model="dataForm.firstTime" placeholder="初审时间" disabled></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="success" @click="success">通过</el-button>
      <el-button type="danger" @click="open">不通过</el-button>
      <el-button @click="visible = false">取消</el-button>
<!--      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>-->
    </span>
  </el-dialog>
</div>
</template>

<script>
import SingleUpload from "../../../components/upload/singleUpload";

export default {
  name: "scrapsubmitwait-add-or-update",
  data() {
    return {
      codeOptions: [
        {
          value: 0,
          label: "A"
        },
        {
          value: 1,
          label: "B"
        }
      ],
      options: [
      ],
      visible: false,
      dataForm: {
        id: 0,
        code:'',
        seqId:0,
        scrapReason:'',
        scrapPhotoUrl:'',
        submitTime:'',
        status:'',
        firstAcceptorName:'',
        firstTime:''
      }
    }
  },
  computed: {
    displayValue() {
      if (this.dataForm.status === '1') {
        return '代初审';
      } else if (this.dataForm.status === '2') {
        return '初审通过';
      } else {
        return '终审通过';
      }
    }
  },
  components:{
    SingleUpload
  },
  methods: {
    success(){
      this.$message({
        type: 'success',
        message: '已通过'
      });
      this.visible = false
    },
    open(){
      this.$prompt('不通过的原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({ value }) => {
        const why = value || ''
        this.$message({
          type: 'success',
          message: '您的不通过的原因是: ' + why
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        });
      });
    },
    getAvatarUrl(url){
      this.dataForm.avatarUrl = url
    },
    removeDomain(item) {
      var index = this.dataForm.jigs.indexOf(item)
      if (index !== -1) {
        this.dataForm.jigs.splice(index, 1)
      }
    },
    addDomain() {
      this.dataForm.jigs.push({
        code: '',
        key: Date.now()
      });
    },
    handleChange(value) {
    },
    clearTopData() {
      this.dataForm.billNo = ''
      this.dataForm.submitId = ''
      this.dataForm.productionLineId = ''
    },
    init(id) {
      this.dataForm.id = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.$http({
            url: `http://localhost:10000/gongjiajumain/scrapsubmit/info/${this.dataForm.id}`,
            method: 'get',
            params: this.$http.adornParams()
          }).then(({data}) => {
            if (data && data.code === 0) {
              console.log(data.scrapSubmit)
              this.dataForm = data.scrapSubmit
            }
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      console.log(this.dataForm)
      // this.$refs['dataForm'].validate((valid) => {
      //   if (valid) {
      //     this.$http({
      //       url: this.$http.adornUrl(`/gongjiajumain/scrapsubmithistory/${!this.dataForm.id ? 'save' : 'update'}`),
      //       method: 'post',
      //       data: this.$http.adornData({
      //         'id': this.dataForm.id || undefined,
      //         'seqId': this.dataForm.seqId,
      //         'code': this.dataForm.code,
      //         'submitId': this.dataForm.submitId,
      //         'usedCount': this.dataForm.usedCount,
      //         'scrapReason': this.dataForm.scrapReason,
      //         'scrapPhotoUrl': this.dataForm.scrapPhotoUrl,
      //         'firstAcceptor': this.dataForm.firstAcceptor,
      //         'firstTime': this.dataForm.firstTime,
      //         'firstReason': this.dataForm.firstReason,
      //         'finalAcceptor': this.dataForm.finalAcceptor,
      //         'finalTime': this.dataForm.finalTime,
      //         'finalReason': this.dataForm.finalReason,
      //         'status': this.dataForm.status
      //       })
      //     }).then(({data}) => {
      //       if (data && data.code === 0) {
      //         this.$message({
      //           message: '操作成功',
      //           type: 'success',
      //           duration: 1500,
      //           onClose: () => {
      //             this.visible = false
      //             this.$emit('refreshDataList')
      //           }
      //         })
      //       } else {
      //         this.$message.error(data.msg)
      //       }
      //     })
      //   }
      // })
    }
  }
}
</script>

<style scoped>

</style>
